/*
 * @Author: lvye
 * @Description:
 * @Date: 2023-07-03 16:17:44
 * @LastEditTime: 2023-07-26 10:35:48
 * @FilePath: \vue3-ts\src\service\index.ts
 */
import HYRequest from "./request"
import { BASE_URL, TIME_OUT } from "./request/config"
import localCache from "@/utils/cache"
const hyRequest = new HYRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptors: (config) => {
      console.log("请求成功的拦截")
      // 携带token
      const token = localCache.getCache("token")
      if (token) {
        config.headers.Authorization = `Bearer ${token}`
      }
      return config
    },
    requestInterceptorsCatch: (err) => {
      console.log("请求失败的拦截")
      return err
    },
    responseInterceptor: (res) => {
      console.log("响应成功的拦截")
      return res
    },
    responseInterceptorCatch: (err) => {
      console.log("响应失败的拦截")
      return err
    }
  }
})
export default hyRequest
